//
//  UFOHeroTimeNewPageCollectionViewCell.m
//  unrivalledForUniverse
//
//  Created by dllo on 16/1/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "UFOHeroTimeNewPageCollectionViewCell.h"

#import "Masonry.h"
@implementation UFOHeroTimeNewPageCollectionViewCell

- (void)dealloc
{
    [_nameL release];
    [_timeL release];
    [_typeL release];
    [_picImageV release];
    [_goodCountL release];
    [_viewCountL release];
    [_playImageV release];
    
    
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

// 创建视图
- (void)createSubviews
{
    self.backgroundColor = [UIColor clearColor];
    
    // 白色背景
    UIImageView *backImageV = [UIImageView new];
    backImageV.image = [UIImage imageNamed:@"bg_share_large"];
    [self.contentView addSubview:backImageV];
    
    [backImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.contentView);
        
    }];
    
    // 视频简图
    self.picImageV = [UIImageView new];
    self.picImageV.image = [UIImage imageNamed:@"zanweitu.png"];
    self.picImageV.layer.masksToBounds = YES;
    self.picImageV.layer.cornerRadius = 5;
    [backImageV addSubview:self.picImageV];
    
    [self.picImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(backImageV);
        make.left.equalTo(backImageV);
        make.size.mas_equalTo(CGSizeMake(self.contentView.bounds.size.width, self.contentView.bounds.size.height * 2 / 3));
        
    }];
    
    // 点赞图标
    UIImageView *goodImageV = [UIImageView new];
    goodImageV.image = [UIImage imageNamed:@"iconfont-dianzan.png"];
    [backImageV addSubview:goodImageV];
    
    [goodImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.picImageV.mas_bottom).offset(5 * SCREENHEIGHT / HEIGHTSIXP);
        make.left.equalTo(self.picImageV).offset(5 * SCREENWIDTH / WIDTHSIXP);
        make.size.mas_equalTo(CGSizeMake(self.contentView.bounds.size.height / 6.0 - 10 * SCREENHEIGHT / HEIGHTSIXP, self.contentView.bounds.size.height / 6.0 - 10 * SCREENHEIGHT / HEIGHTSIXP));
        
    }];
    
    // 点赞label
    self.goodCountL = [UILabel new];
    self.goodCountL.backgroundColor = [UIColor clearColor];
    self.goodCountL.textColor = [UIColor colorWithWhite:0.200 alpha:1.000];
    self.goodCountL.font = [UIFont systemFontOfSize:12.0 * SCREENHEIGHT / HEIGHTSIXP];
    [backImageV addSubview:self.goodCountL];
    
    [self.goodCountL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(goodImageV);
        make.left.equalTo(goodImageV.mas_right).offset(5 * SCREENWIDTH / WIDTHSIXP);
        make.width.equalTo(goodImageV.mas_width).multipliedBy(3);
        make.height.equalTo(goodImageV);
        
    }];
    
    // 观看图标
    UIImageView *viewImageV = [UIImageView new];
    viewImageV.image = [UIImage imageNamed:@"iconfont-iconguankanshu"];
    [backImageV addSubview:viewImageV];
    
    [viewImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(goodImageV);
        make.left.equalTo(self.goodCountL.mas_right).offset(5 * SCREENWIDTH / WIDTHSIXP);
        make.size.mas_equalTo(CGSizeMake(self.contentView.bounds.size.height / 6.0 - 10 * SCREENHEIGHT / HEIGHTSIXP, self.contentView.bounds.size.height / 6.0 - 10 * SCREENHEIGHT / HEIGHTSIXP));
        
    }];
    
    // 观看label
    self.viewCountL = [UILabel new];
    self.viewCountL.backgroundColor = [UIColor clearColor];
    self.viewCountL.textColor = [UIColor colorWithWhite:0.200 alpha:1.000];
    self.viewCountL.font = [UIFont systemFontOfSize:12.0 * SCREENHEIGHT / HEIGHTSIXP];
    [backImageV addSubview:self.viewCountL];
    
    [self.viewCountL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(viewImageV);
        make.left.equalTo(viewImageV.mas_right).offset(5 * SCREENWIDTH / WIDTHSIXP);
        make.width.equalTo(viewImageV.mas_width).multipliedBy(3);
        make.height.equalTo(viewImageV);
        
    }];
    
    // 时间label
    self.timeL = [UILabel new];
    self.timeL .backgroundColor = [UIColor clearColor];
    self.timeL.textColor = [UIColor grayColor];
    self.timeL.font = [UIFont systemFontOfSize:12.0 * SCREENHEIGHT / HEIGHTSIXP];
    self.timeL.textAlignment = NSTextAlignmentRight;
    [backImageV addSubview:self.timeL];
    
    [self.timeL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(viewImageV.mas_bottom).offset(5 * SCREENHEIGHT / HEIGHTSIXP);
        make.left.equalTo(self.goodCountL.mas_left);
        make.right.equalTo(backImageV).offset(- 5 * SCREENWIDTH / WIDTHSIXP);
        make.height.equalTo(self.viewCountL);
        
        
    }];
    
    // 黑条
    UIView *blackView = [UIView new];
    blackView.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.583];
    [backImageV addSubview:blackView];
    
    [blackView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.picImageV);
        make.size.mas_equalTo(CGSizeMake(self.contentView.bounds.size.width, self.contentView.bounds.size.height * 2 / 3 / 5));
        
    }];
    
    // 头像
    UIImageView *headerImageV = [UIImageView new];
    headerImageV.image = [UIImage imageNamed:@"头像.jpg"];
    headerImageV.layer.masksToBounds = YES;
    headerImageV.layer.cornerRadius = 15 * SCREENHEIGHT / HEIGHTSIXP;
    [backImageV addSubview:headerImageV];
    
    [headerImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(backImageV).offset(5 * SCREENWIDTH / WIDTHSIXP);
        make.bottom.equalTo(self.picImageV).offset(- 5 * SCREENHEIGHT / HEIGHTSIXP);
        make.size.mas_equalTo(CGSizeMake(30 * SCREENHEIGHT / HEIGHTSIXP, 30 * SCREENHEIGHT / HEIGHTSIXP));
        
    }];
    
    // 标题label
    self.nameL = [UILabel new];
    self.nameL.backgroundColor = [UIColor clearColor];
    self.nameL.font = [UIFont systemFontOfSize:12.0 * SCREENHEIGHT / HEIGHTSIXP];
    self.nameL.textAlignment = NSTextAlignmentLeft;
    self.nameL.textColor = [UIColor whiteColor];
    [backImageV addSubview:self.nameL];
    
    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(headerImageV.mas_right).offset(5 * SCREENWIDTH / WIDTHSIXP);
        make.top.equalTo(blackView);
        make.size.mas_equalTo(CGSizeMake(self.contentView.bounds.size.width - 45 * SCREENWIDTH / WIDTHSIXP, self.contentView.bounds.size.height * 2 / 3 / 5));
        
    }];
    
    // 播放imageV
    self.playImageV = [UIImageView new];
    self.playImageV.image = [UIImage imageNamed:@"large_cover_play_hover.tiff"];
    [backImageV addSubview:self.playImageV];
    
    [self.playImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.mas_equalTo(self.picImageV);
        make.size.mas_equalTo(CGSizeMake(40 * SCREENHEIGHT / HEIGHTSIXP, 40 * SCREENHEIGHT / HEIGHTSIXP));
        
    }];
    
    // 类型label
    self.typeL = [UILabel new];
    self.typeL.backgroundColor = [UIColor clearColor];
    self.typeL.layer.masksToBounds = YES;
    self.typeL.layer.cornerRadius = 5;
    self.typeL.font = [UIFont systemFontOfSize:12.0 * SCREENHEIGHT / HEIGHTSIXP];
    self.typeL.textAlignment = NSTextAlignmentLeft;
    self.typeL.textColor = [UIColor whiteColor];
    [backImageV addSubview:self.typeL];

    [self.typeL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(backImageV);
        make.right.equalTo(backImageV);
        make.height.mas_equalTo(@(20 * SCREENHEIGHT / HEIGHTSIXP));
        
    }];
}

// 根据类型确定typeL大小、颜色和内容
- (void)createTypeLabelWithTypeNum:(NSString *)typeNum
{
    int num = [typeNum intValue];
    switch (num) {
        case 1:
            self.typeL.hidden = NO;
            self.typeL.backgroundColor = [UIColor colorWithRed:0.124 green:1.000 blue:0.108 alpha:1.000];
            self.typeL.text = @"人机模式";
            break;
        case 2:
            self.typeL.hidden = NO;
            self.typeL.backgroundColor = [UIColor colorWithRed:1.000 green:0.108 blue:0.289 alpha:1.000];
            self.typeL.text = @"匹配模式";
            break;
        case 3:
            self.typeL.hidden = NO;
            self.typeL.backgroundColor = [UIColor colorWithRed:0.205 green:0.778 blue:1.000 alpha:1.000];
            self.typeL.text = @"大乱斗模式";
            break;
        case 4:
            self.typeL.hidden = NO;
            self.typeL.backgroundColor = [UIColor colorWithRed:1.000 green:0.492 blue:0.039 alpha:1.000];
            self.typeL.text = @"排位模式";
            break;
        case 5:
            self.typeL.hidden = NO;
            self.typeL.backgroundColor = [UIColor colorWithRed:0.629 green:0.095 blue:1.000 alpha:1.000];
            self.typeL.text = @"自定义模式";
            break;
        case 6:
            self.typeL.hidden = YES;
            break;
    }
}

@end
